<?php
  global $_GPC, $_W;
        $uniacid = $this->_uniacid;
        $newhouse_id = $_GPC['newhouse_id'];
        $keyword = $_GPC['keyword'];
        $tags = 0;
        if ($_GPC['tags']) {
            $tags = $_GPC['tags'];
        }
        /*获取分类*/
        if(isset($_GPC['enews']) && ($_GPC['enews'] =='category')){
            $sqladd = "  and parentid=0  ";
            if(!empty($_GPC['cid'])){
                $cid = intval($_GPC['cid']);
                $sqladd = " and (id='$cid' or parentid='$cid') ";
            }
                                          /* 分类统计 */
            $ret  = pdo_fetchall("select * from ".tablename("site_category")." where uniacid='$uniacid' $sqladd and enabled=1");
            $category = array();    
            foreach ($ret as $k => $cat) {
                $key = $cat['id'];
                $category[$key]['name'] = $cat['name'];
                $category[$key]['tags'] = $key;
                $category[$key]['selected'] = ($key == $tags ? 1 : 0);
                $category[$key]['total'] = 0;
                     $thumb = iunserializer($cat['css']);
                $category[$key]['thumb'] = tomedia($thumb['thumb']);
            }
            $this->result(0, 'success', $category);
        }
        /*按栏目获取资讯频道*/
 
                /*获取一片文章*/
 if(isset($_GPC['enews']) && ($_GPC['enews'] =='show')){
            $id = intval($_GPC['aid']);    /* 分类统计 */
            $tid =  intval($_GPC['tid']) ? intval($_GPC['tid']) : 10;
            $ret  = pdo_fetch("select * from ".tablename("kbwdl_house_saleinfo")." where uniacid='$uniacid' and tid='$tid'  and disabled=0 and id='$id'");
            $ret['newstext'] = htmlspecialchars_decode($ret['newstext']);
            
             /* 处理房源信息 获取腾讯实际播放地址 */
        preg_match('/<iframe(.*?)src="(.*?)"/', $ret['newstext'], $arr);
        $ret['vurl'] = $arr[2];
        $urlinfo = parse_url($arr[2]);
        if(!empty($urlinfo['query'])){
            $query = explode('&', $urlinfo['query']);
             $a2 = array();
                foreach ($query as $q)
                {
                    $a1 = explode('=', $q);
                    $a2[$a1[0]] = $a1[1];
                }
        }
        $ret['videoid'] = $a2['vid'];
        $furl_real = '';
        if(!empty($ret['videoid'])){
          // echo  $a3 = file_get_contents('http://vv.video.qq.com/getinfo?vids='.$info['videoid'].'&platform=101001&charge=0&otype=json');
           $a3 = file_get_contents('https://vv.video.qq.com/getinfo?otype=json&appver=3.2.19.333&platform=11&defnpayver=1&vid='.$ret['videoid']);
            $a3  = str_replace('QZOutputJson=', '', rtrim($a3,';'));
            $a3 = json_decode($a3, true);
          
            $fvkey = $a3['vl']['vi'][0]['fvkey'];
            $fn = $a3['vl']['vi'][0]['fn'];
            $furl = $a3['vl']['vi'][0]['ul']['ui'][0]['url'];
            $furl_real = $furl .$fn .'?vkey='.$fvkey;
        }
        $ret['videoinfo'] = $furl_real;
        /* 结束腾讯视频获取 */
         $ret['thumb'] = tomedia($ret['thumb']);
       /*获取自己上传的视频*/
        if(!empty($info['video']) && strpos($info['video'],'mages')){
            $ret['video'] = tomedia($info['video']);           
        }else{
            /*获取后台插入的视频*/
            preg_match('/<video(.*?)src="(.*?)"/', $ret['newstext'], $arr);
            $ret['video'] = $arr[2];
        } 
       /*获取全部图片*/
        $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.bmp|\.png]))[\'|\"].*?[\/]?>/";
	preg_match_all($pattern,$ret['newstext'],$match);
	$ret['allpics'] = $match[1]; 
         $ret['gpoun_num'] = $ret['gpoun_num']==1?1:0;
            /*更新浏览*/
            $ret['onclick'] = $ret['onclick']+1;
            pdo_update('kbwdl_house_saleinfo', array('onclick'=> $ret['onclick'] ), array('id'=> $id));
            $this->result(0, 'success', $ret);
 }
 /*获取首页通告滚动*/
 if(isset($_GPC['enews']) && ($_GPC['enews'] =='anotice')){
      $limit = 4;
        if (isset($_GPC['limit']) && !empty($_GPC['limit'])) {
            $limit = intval($_GPC['limit']);
        }
      $sql_add = " s.uniacid='$uniacid' and s.tid=10  and s.fid>0  and s.disabled=0 and s.posid=1 ";
      $ret = pdo_fetchall("select id,title  from " . tablename("kbwdl_house_saleinfo") .
                " s   where $sql_add order by s.addtime desc limit 0, $limit ");
      $list = [];
      if(!empty($ret)){
          $list = $ret;
      }
      $this->result(0, 'success', $list);
 }     
/*资讯新闻列表*/
        $limit = 4;
        if (isset($_GPC['limit']) && !empty($_GPC['limit'])) {
            $limit = intval($_GPC['limit']);
        }
        $sql_add = " s.uniacid='$uniacid' and s.tid=10  and s.fid>0  and s.disabled=0 ";
 
       if ($tags) {
            $sql_add.=" and s.fid in (select c.id from ".tablename("site_category")." as c where (c.id='$tags' or c.parentid='$tags') and c.enabled=1 ) ";
        }else{
           $sql_add.=" and s.fid in (select c.id from ".tablename("site_category")." as c where  c.enabled=1 ) "; 
        }
        
        if ($keyword) {
            $sql_add.=" and ( s.title like '%$keyword%' )";
        }
        $page = max(1, $_GPC['page']);
        $pagesize = $limit;
        $startlimit = ($page - 1) * $pagesize;
        $category = array();
        if(isset($_GPC['total']) && ! empty($_GPC['total'])){
            $total = $_GPC['total'];   
       
        }else{
             $total = pdo_fetchcolumn("select count(*)  from ". tablename("kbwdl_house_saleinfo") ." s where $sql_add ");

        }
       
        $ret = pdo_fetchall("select id,title,fid,fname,smalltext,thumb,addtime  from " . tablename("kbwdl_house_saleinfo") .
                " s   where $sql_add order by s.addtime desc limit $startlimit,$pagesize ");
        if (!empty($ret)) {
            foreach ($ret as $key => $val) {
                $ret[$key]['category'] = $this->other['saletype'][$val['tags']];
                $ret[$key]['showtime'] = date('Y年m月d日', strtotime($val['addtime']));
                $ret[$key]['thumb'] = tomedia($val['thumb']);
               
            }
        }
        $data['salelist'] = $ret;

        $data['category'] = $category;
        $data['total'] = $total;
        $this->result(0, 'success', $data);
?>
